package com.reden;

import com.melloware.jintellitype.HotkeyListener;
import com.melloware.jintellitype.JIntellitype;

public class KeyListener {
    private HotkeyListener hotkeyListener;

    public KeyListener(Automatic automatic) {
        unregisterKey();
        registerKey();
        this.hotkeyListener = new HotkeyListener() {
            public void onHotKey(int code) {
                switch (code) {
                    case 1: {
                        automatic.setEnable(true);
                        break;
                    }
                    case 2: {
                        automatic.setEnable(false);
                        break;
                    }
                }
            }
        };
        setKeyEvent(hotkeyListener);
    }

    public static void registerKey() {
        JIntellitype.getInstance().registerHotKey(1, JIntellitype.MOD_ALT, 192);
        JIntellitype.getInstance().registerHotKey(2, 0, 20);
    }

    public static void unregisterKey() {
        JIntellitype.getInstance().unregisterHotKey(1);
        JIntellitype.getInstance().unregisterHotKey(2);

    }

    public static void setKeyEvent(HotkeyListener hotkeyListener) {
        JIntellitype.getInstance().addHotKeyListener(hotkeyListener);
    }

    public static void removeKeyEvent(HotkeyListener hotkeyListener) {
        JIntellitype.getInstance().removeHotKeyListener(hotkeyListener);
    }
}
